import 'package:flutter/material.dart';

// 模拟光标
class VerificationCursor extends StatefulWidget {
  VerificationCursor({this.color, this.width, this.decoration, this.height});

  // 光标颜色
  final Color color;
  final Decoration decoration;

  // 光标宽度
  final double width;
  final double height;

  @override
  State<StatefulWidget> createState() => _VerificationCursorState();
}

class _VerificationCursorState extends State<VerificationCursor>
    with SingleTickerProviderStateMixin {
  AnimationController _controller;

  @override
  void initState() {
    _controller =
        AnimationController(duration: Duration(milliseconds: 500), vsync: this)
          ..addStatusListener((status) {
            if (status == AnimationStatus.completed) {
              _controller.reverse();
            } else if (status == AnimationStatus.dismissed) {
              _controller.forward();
            }
          });
    _controller.forward();

    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return FadeTransition(
      opacity: _controller,
      child: Container(
          width: widget.width,
          height: widget.height,
          decoration: widget.decoration ?? BoxDecoration(color: widget.color)),
    );
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }
}
